<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Create the cart-site to show all products in cart
 * for the customer
 * get cart.show.tpl.php
 * used by cart.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
// include options-calculate-class
$pagefile = 'module/class/option.calculate.class.php';
if (is_file($pagefile))
	include_once($pagefile);
// get products from cart and calculate prices
$cart = $refCart->getProducts();
$price = '';
$tax = array();
$cartx = array();
$pricex = 0;

$refCart->addToTotalPrice(0, 0, TRUE);
if ($refCart->isProduct() >= 1)
{
	foreach ($cart as $product)
	{
		$pricePerItem = $refCart->productPricePerItem($product['cart_product_id'], $product['number'], $product);
		$priceTotal = $refCart->productPrice($product['cart_product_id'], $product['number'], $product);
		$refCart->addToTotalPrice($priceTotal, $product['cart_product_id']);

		// TODO: Update the product name with the option descriptions
		$tax = $refCart->getTax($priceTotal, $product['cart_product_id']);

		$cartx[] = array(
		 'sku' => $product['sku'],
		 'product' => $product['product'] . $refCart->optionsText2Html($product['optionsText']),//$product['optionsText'],
		 'pricePerItem' => $pricePerItem,
		 'priceTotal' => $priceTotal,
		 'tax' => $refCart->getTax($priceTotal, $product['cart_product_id'], FALSE),
		 'number' => $product['number'],
		 'refresh' =>
		 '<form action="index.php?page=article&title=' . $product['cart_product_id'] .
		 '&name=' . $product['product'] . '&cart=newnumber" method="post" style="display: inline;">' .
		 '<input name="' . $product['cart_product_id'] . 'number" id="' . $product['cart_product_id'] . 'number" value="1" size="4" type="text">' .
		 '<input name="id" value="' . $product['cart_product_id'] . '" type="hidden">' .
		 '<input class="number_cart" name="refresh" title="' . _('Refresh') .
		 '" src="template/images/cart_refresh.png" alt="' . _('refresh') .
		 '" type="image">' .
		 '</form>',
		 'delete' =>
		 '<form action="index.php?page=article&title=' . $product['cart_product_id'] .
		 '&name=' . $product['product'] . '&cart=delete" method="post" style="display: inline;">' .
		 '<input name="id" value="' . $product['cart_product_id'] . '" type="hidden">' .
		 '<input class="delete_product" name="delete" title="' . _('Delete Product') .
		 '" src="template/images/cart_delete.png" alt="' . _('delete') .
		 '" type="image">' .
		 '</form>');
	}
	$refPage->assign('productList', $cartx);

	$data = array('config_value', 'config_value2');
	db::getInstance()->where('config_key', 'ShippingPrice');
	$shipping = db::getInstance()->getOne('config', NULL, $data);

	$refPage->assign('price', $refCart->getTotalPrice(TRUE));
	$refPage->assign('tax', $refCart->getTotalPriceTax(TRUE));

	$refPage->assign('formstart',
		'<form action = "' . URL . '?page=cart&title=order' .
		'&name=' . _('Shoppingcart') . '&cart=order" method = "post">');
	$refPage->assign('formend', '</form>');

	$refPage->assign('order_button',
		'<input class="btn_order" name="btn_order" title="' . _('Buy now') .
		'" src="template/images/btn_to_order.png" alt="' . _('Buy now') .
		'" type="image">');
	$refPage->assign('back_button',
		'<a title="' . _('Back') . '" href="' . pagepointer::getBackPage() . '">' .
		'<img src="/template/images/btn_back.png" alt = "' .
		_('Back') . '" titel = "Warenkorb"></a>');

	$refPage->addtpl('content', '/' . $page . '/' . $title . '.tpl.php');
}
else
{
	header('location: ' . URL);
	exit;
}
?>
